package com.zhanglijie.base.fiberAndThreadCompare;

import java.util.concurrent.ExecutionException;

import co.paralleluniverse.fibers.Fiber;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/3/13 0013 0:59
 */
public class MyFiberTest {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        long cur = System.currentTimeMillis();
        // int num = 100000; 3390
        int num = 100; //422
        Fiber<Void>[] fibers = new Fiber[num];
       for(int i=0;i<num;i++){
           fibers[i] = new Fiber(()->{
               calcute();
           });
       }
       for(int i=0;i<num;i++){
           fibers[i].start();
           fibers[i].join();
       }
        System.out.println("总计耗时"+(System.currentTimeMillis()-cur));
    }

    private static void calcute() {
        int result = 0;
        for(int i=0;i<1000;i++){
            for(int j=0;j<2000;j++){
                result++;
            }
        }
        System.out.println("该纤程任务执行完毕！！！");
    }
}
